package com.lfy.controller;

import com.lfy.modules.blog.domain.dto.leave.LeaveMsgDTO;
import com.lfy.modules.blog.domain.vo.web.LeaveMsgVO;
import com.lfy.modules.blog.service.LeaveMessageService;
import com.lfy.modules.common.domain.PageResultVO;
import com.lfy.modules.common.domain.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/web/leave")
public class LeaveMsgController {
    @Resource
    private LeaveMessageService leaveMessageService;

    /**
     * 获取根节点留言列表
     * @param pageNum 页码
     * @param pageSize  pageSize
     * @param url 留言来源
     * @return PageResultVO<LeaveMsgVO>
     */
    @GetMapping("/getLeaveMsg")
    public R<PageResultVO<LeaveMsgVO>> getLeaveMsg(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, @RequestParam("url") String url) {
        return leaveMessageService.getLeaveMsgByPage(pageNum, pageSize, url);
    }
    /**
     * 获取子节点留言列表
     *
     */
    @GetMapping("/getChildLeaveMsg")
    public R<List<LeaveMsgVO>> getChildLeaveMsg(@RequestParam("url")String url, @RequestParam("parentMsgId") Long parentMsgId) {
        return leaveMessageService.getChildLeaveMsg(url, parentMsgId);
    }
    @PostMapping("/addLeaveMsg")
    public R<Void> addLeaveMsg(@RequestBody @Validated LeaveMsgDTO dto) {
        return leaveMessageService.addLeaveMsg(dto);
    }
    /**
     * 点赞
     */
    @PostMapping("/like")
    public R<Void> like(@RequestParam("msgId") Long msgId,Integer type) {
        return leaveMessageService.like(msgId,type);
    }

}
